from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-01 14:06:48.655329
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 01, Mar, 2021
Time: 14:06:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4628
Nobs: 217.000 HQIC: -47.2984
Log likelihood: 2512.12 FPE: 1.63272e-21
AIC: -47.8646 Det(Omega_mle): 1.08847e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.471253 0.135362 3.481 0.000
L1.Burgenland 0.072951 0.069371 1.052 0.293
L1.Kärnten -0.213736 0.058939 -3.626 0.000
L1.Niederösterreich 0.160787 0.157095 1.024 0.306
L1.Oberösterreich 0.242374 0.140527 1.725 0.085
L1.Salzburg 0.210132 0.074648 2.815 0.005
L1.Steiermark 0.100341 0.100659 0.997 0.319
L1.Tirol 0.131533 0.067603 1.946 0.052
L1.Vorarlberg -0.012427 0.061372 -0.202 0.840
L1.Wien -0.148298 0.130779 -1.134 0.257
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.476114 0.162626 2.928 0.003
L1.Burgenland 0.011548 0.083343 0.139 0.890
L1.Kärnten 0.350634 0.070810 4.952 0.000
L1.Niederösterreich 0.089929 0.188736 0.476 0.634
L1.Oberösterreich -0.113327 0.168832 -0.671 0.502
L1.Salzburg 0.197548 0.089683 2.203 0.028
L1.Steiermark 0.198393 0.120933 1.641 0.101
L1.Tirol 0.141818 0.081220 1.746 0.081
L1.Vorarlberg 0.156053 0.073733 2.116 0.034
L1.Wien -0.495382 0.157121 -3.153 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313630 0.062865 4.989 0.000
L1.Burgenland 0.101615 0.032217 3.154 0.002
L1.Kärnten -0.020646 0.027372 -0.754 0.451
L1.Niederösterreich 0.074843 0.072958 1.026 0.305
L1.Oberösterreich 0.304344 0.065264 4.663 0.000
L1.Salzburg 0.006258 0.034668 0.181 0.857
L1.Steiermark -0.012038 0.046748 -0.258 0.797
L1.Tirol 0.076811 0.031396 2.446 0.014
L1.Vorarlberg 0.098669 0.028503 3.462 0.001
L1.Wien 0.063279 0.060737 1.042 0.297
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.224289 0.068815 3.259 0.001
L1.Burgenland 0.000662 0.035267 0.019 0.985
L1.Kärnten 0.018665 0.029963 0.623 0.533
L1.Niederösterreich 0.022873 0.079864 0.286 0.775
L1.Oberösterreich 0.396439 0.071441 5.549 0.000
L1.Salzburg 0.086526 0.037950 2.280 0.023
L1.Steiermark 0.174961 0.051173 3.419 0.001
L1.Tirol 0.042761 0.034368 1.244 0.213
L1.Vorarlberg 0.083747 0.031200 2.684 0.007
L1.Wien -0.051914 0.066486 -0.781 0.435
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.514300 0.135010 3.809 0.000
L1.Burgenland 0.063140 0.069191 0.913 0.361
L1.Kärnten 0.014531 0.058785 0.247 0.805
L1.Niederösterreich -0.028198 0.156686 -0.180 0.857
L1.Oberösterreich 0.142940 0.140162 1.020 0.308
L1.Salzburg 0.063950 0.074454 0.859 0.390
L1.Steiermark 0.108924 0.100397 1.085 0.278
L1.Tirol 0.211932 0.067427 3.143 0.002
L1.Vorarlberg 0.027177 0.061213 0.444 0.657
L1.Wien -0.108806 0.130440 -0.834 0.404
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193054 0.097450 1.981 0.048
L1.Burgenland -0.013573 0.049942 -0.272 0.786
L1.Kärnten -0.008557 0.042431 -0.202 0.840
L1.Niederösterreich 0.056639 0.113097 0.501 0.617
L1.Oberösterreich 0.404773 0.101169 4.001 0.000
L1.Salzburg -0.013812 0.053741 -0.257 0.797
L1.Steiermark -0.016506 0.072467 -0.228 0.820
L1.Tirol 0.181314 0.048669 3.725 0.000
L1.Vorarlberg 0.043583 0.044183 0.986 0.324
L1.Wien 0.180089 0.094152 1.913 0.056
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246934 0.125513 1.967 0.049
L1.Burgenland 0.050625 0.064324 0.787 0.431
L1.Kärnten -0.039422 0.054650 -0.721 0.471
L1.Niederösterreich -0.055580 0.145664 -0.382 0.703
L1.Oberösterreich -0.066979 0.130303 -0.514 0.607
L1.Salzburg 0.058950 0.069216 0.852 0.394
L1.Steiermark 0.392116 0.093335 4.201 0.000
L1.Tirol 0.463616 0.062684 7.396 0.000
L1.Vorarlberg 0.155255 0.056907 2.728 0.006
L1.Wien -0.203013 0.121264 -1.674 0.094
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127516 0.150505 0.847 0.397
L1.Burgenland 0.025957 0.077132 0.337 0.736
L1.Kärnten -0.071270 0.065532 -1.088 0.277
L1.Niederösterreich 0.186684 0.174670 1.069 0.285
L1.Oberösterreich -0.009580 0.156249 -0.061 0.951
L1.Salzburg 0.252539 0.082999 3.043 0.002
L1.Steiermark 0.138449 0.111920 1.237 0.216
L1.Tirol 0.051101 0.075166 0.680 0.497
L1.Vorarlberg 0.064526 0.068238 0.946 0.344
L1.Wien 0.237388 0.145411 1.633 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.575340 0.081096 7.095 0.000
L1.Burgenland -0.034444 0.041561 -0.829 0.407
L1.Kärnten -0.016306 0.035311 -0.462 0.644
L1.Niederösterreich -0.012608 0.094117 -0.134 0.893
L1.Oberösterreich 0.315211 0.084191 3.744 0.000
L1.Salzburg 0.018087 0.044722 0.404 0.686
L1.Steiermark -0.009425 0.060306 -0.156 0.876
L1.Tirol 0.078872 0.040502 1.947 0.051
L1.Vorarlberg 0.119993 0.036768 3.263 0.001
L1.Wien -0.027447 0.078351 -0.350 0.726
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134238 0.033548 0.188672 0.246476 0.057733 0.121197 -0.039931 0.166084
Kärnten 0.134238 1.000000 0.007034 0.199361 0.167540 -0.117989 0.154181 0.012632 0.318695
Niederösterreich 0.033548 0.007034 1.000000 0.290028 0.076261 0.244532 0.164670 0.051510 0.355406
Oberösterreich 0.188672 0.199361 0.290028 1.000000 0.297552 0.290762 0.115545 0.080974 0.143740
Salzburg 0.246476 0.167540 0.076261 0.297552 1.000000 0.139901 0.057482 0.089794 0.000758
Steiermark 0.057733 -0.117989 0.244532 0.290762 0.139901 1.000000 0.124687 0.118567 -0.105019
Tirol 0.121197 0.154181 0.164670 0.115545 0.057482 0.124687 1.000000 0.183876 0.168951
Vorarlberg -0.039931 0.012632 0.051510 0.080974 0.089794 0.118567 0.183876 1.000000 0.030223
Wien 0.166084 0.318695 0.355406 0.143740 0.000758 -0.105019 0.168951 0.030223 1.000000